export default{
	// 开启命名空间
	namespaced:true,
	
	state:()=>({
		//收货地址
		address:JSON.parse(uni.getStorageSync('address') || '{}'),
		
		//登录之后的token字符串
		token:uni.getStorageSync('token') || '',
		// token:'zheshiwozijidingyidetokenzifuchuan',
		
		//用户的基本信息
		userinfo:JSON.parse(uni.getStorageSync('userinfo') || '{}'),
		
		//重定向的对象
		 redirectInfo: null
		
	}),	
	
	mutations:{
		updateAddress(state,address){
			state.address = address
			// console.log('vuexaddress:',state.address);
			// 调用 m_user 模块下的 saveAddressToStorage 方法将 address 对象持久化存储到本地
			this.commit('m_user/saveadrToStorage')
		},
		
		saveadrToStorage(state){
			uni.setStorageSync('address',JSON.stringify(state.address))
		},
		
		updateUserInfo(state,userinfo){
			state.userinfo = userinfo
			// console.log('stateuserinfo:',state.userinfo);
			// 通过 this.commit() 方法，
			//调用 m_user 模块下的 saveUserInfoToStorage 方法，将 userinfo 对象持久化存储到本地
			this.commit('m_user/saveUserInfoToStorage')
		},
		
		//将userinfo保存到本地
		saveUserInfoToStorage(state){
			uni.setStorageSync('userinfo',JSON.stringify(state.userinfo))
		},
		
		// 更新 token 字符串
		updateToken(state,Token){
			state.token = Token
			console.log('token:',Token);
			// 持久化存储到本地
			this.commit('m_user/saveTokenStorage')
		},
		
		saveTokenStorage(state){
			uni.setStorageSync('token',state.token)
		},
		
		 updateRedirectInfo(state,info){
			 state.redirectInfo = info
			 console.log('redirectInfo:',state.redirectInfo);
		 }
		
	},
	
	getters:{
		addstr(state){
			if(!state.address.provinceName) return ''
			
			return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
		},
	}
}